package de.gameduell.framework.gui.animation {
	import Singularity.Geom.Composite;
	
	import de.gameduell.framework.util.Library;
	
	import flash.display.Sprite;
	import flash.events.EventDispatcher;
	import flash.geom.Point;	

	/**
	 * @author cbra
	 */
	public class PathPrintTween extends EventDispatcher implements Tweenable{

		public static var CONTAINER_NAME:String = "red_dot_container";
		private var timeTween:GDTween;
		private var printedObjectId:String;
		private var _composite:Composite;
		private var lastPos:Point;
		private var _distance:Number;
		private var library:Library;
		private var _container:Sprite;

		
		public function PathPrintTween(aPrintedObjectId:String,parentContainer:Sprite,aComposite:Composite,aDistance:Number,EaseType:Function,startValue:Number,endValue:Number, duration:Number, useSeconds:Boolean) {
			printedObjectId = aPrintedObjectId;
			timeTween = new GDTween(this,"t",EaseType,startValue,endValue,duration,useSeconds);	
			_composite = aComposite;
			_distance = aDistance;
			lastPos = new Point(_composite.getX(0),_composite.getY(0));
			_container = new Sprite();
			_container.name = CONTAINER_NAME;
			parentContainer.addChild(_container);
			library = Library.getInstance();
		}
		
		public function set t(time:Number):void{
			var currPos:Point = new Point(_composite.getX(time),_composite.getY(time));
			if(Point.distance(currPos,lastPos) >= _distance){
				lastPos = currPos;
				var sprite:Sprite = library.createSprite(printedObjectId);
				sprite.x = lastPos.x;
				sprite.y = lastPos.y;
				_container.addChild(sprite);
			}
		}
		
		public function start():void {
			timeTween.start();
		}
		
		public function stop():void {
			timeTween.start();
		}
		
		public function get isPlaying():Boolean {
			return timeTween.isPlaying;
		}
	}

}
